package com.zuxia.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zuxia.entity.Recruit;
import com.zuxia.service.IRecruitService;
import com.zuxia.uilt.PageModel;

@Controller()
@Scope("prototype")
@ParentPackage("struts-default")
@Namespace("/")
@Results({
		@Result(name = "selectRec", type = "dispatcher", location = "/admin/chaRecruit.jsp"),
		@Result(name = "empty", type = "dispatcher", location = "/admin/empty.jsp"),
		@Result(name = "Y", type = "redirectAction", location = "/findRecruit"),
		@Result(name = "fsrec", type = "dispatcher", location = "/admin/addRecruit.jsp"), 
		@Result(name = "selectQtRec", type = "dispatcher", location = "/joinUs.jsp"),
		@Result(name = "selectQtzxRec", type = "dispatcher", location = "/joinUs_acceptOffer.jsp")
})
public class RecruitAction extends ActionSupport implements
		ModelDriven<Recruit> {
	private Recruit recruit = new Recruit();

	@Override
	public Recruit getModel() {
		// TODO Auto-generated method stub
		return recruit;
	}

	@Autowired
	private IRecruitService recservice;
	private int pageNo = 1;// ��̬�ı� ҳ��ȡ��
	private int pSize = 5;// �̶�����
	private String yname = "";
	private PageModel<?> pm;

	public PageModel<?> getPm() {
		return pm;
	}

	public void setPm(PageModel<?> pm) {
		this.pm = pm;
	}

	public Recruit getRecruit() {
		return recruit;
	}

	public void setRecruit(Recruit recruit) {
		this.recruit = recruit;
	}

	public IRecruitService getRecservice() {
		return recservice;
	}

	public void setRecservice(IRecruitService recservice) {
		this.recservice = recservice;
	}

	public String getYname() {
		return yname;
	}

	public void setYname(String yname) {
		this.yname = yname;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	@Action("findRecruit")
	public String findRecruit() {
		pm = new PageModel();
		List list = recservice.selectRecruit(pageNo, yname, pSize);
		if (list.size() > 0) {
			pm.setList(list);
			pm.setCount(recservice.recsize());
			pm.setPageNo(pageNo);
			pm.setPageSize(5);
			ActionContext.getContext().put("rec", pm);
			int sumPage = pm.getSumPage();

			ActionContext.getContext().put("sumPage", sumPage);
			return "selectRec";
		}
		return "empty";
	}

	// ɾ��
	@Action("deleteRecruit")
	public String deleteRecruit() {
		recservice.delrec(recruit);
		return "Y";
	}

	// ���
	@Action("addRecruit")
	public String addRecruit() {
		recservice.addrec(recruit);
		return "Y";
	}

	// ����id��ѯ����
	@Action("findupdateRecruit")
	public String findupdateRecruit() {
		recruit = recservice.findupdateRecruit(recruit);
		return "fsrec";
	}

	// 修改
	@Action("updaetRecruit")
	public String updaetRecruit() {
		recservice.updrec(recruit);
		return "Y";
	}

	// 前台显示招聘信息
	@Action("findQtRecruit")
	public String findQtRecruit() {
		pm = new PageModel();
		List list = recservice.selectRecruit(pageNo, yname, pSize);

		pm.setList(list);
		pm.setCount(recservice.recsize());
		pm.setPageNo(pageNo);
		pm.setPageSize(5);
		ActionContext.getContext().put("rec", pm);
		int sumPage = pm.getSumPage();

		ActionContext.getContext().put("sumPage", sumPage);
		return "selectQtRec";

	}
	//前台点击在线招聘跳转过去显示招聘岗位
	@Action("findQtzxRecruit")
	public String findQtzxRecruit() {
		pm = new PageModel();
		List list = recservice.selectRecruit(pageNo, yname, pSize);

		pm.setList(list);
		pm.setCount(recservice.recsize());
		pm.setPageNo(pageNo);
		pm.setPageSize(5);
		ActionContext.getContext().put("rec", pm);
		int sumPage = pm.getSumPage();

		ActionContext.getContext().put("sumPage", sumPage);
		return "selectQtzxRec";

	}
}
